package com.v2.k28;


import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

import javax.sql.DataSource;

@Component
public class TransactionTemplateService {

	private JdbcTemplate jdbcTemplate;
	private TransactionTemplate transactionTemplate;

	public TransactionTemplateService(TransactionTemplate transactionTemplate, DataSource dataSource) {
		this.transactionTemplate = transactionTemplate;
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public void test() {

		transactionTemplate.execute(new TransactionCallbackWithoutResult() {
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				jdbcTemplate.execute("insert into order_item_his(order_item_id, his_shard) values(133,'2021-06-06');");
			}
		});

	}

}
